package com.itbaizhan.openhis.controller.system;

import com.itbaizhan.openhis.domain.Dept;
import com.itbaizhan.openhis.dto.DeptDto;
import com.itbaizhan.openhis.service.DeptService;
import com.itbaizhan.openhis.utils.ShiroSecurityUtils;
import com.itbaizhan.openhis.vo.AjaxResult;
import com.itbaizhan.openhis.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:科室控制
 */
@RestController
@RequestMapping("system/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 分页查询
     * @param deptDto
     * @return
     */
    @GetMapping("listDeptForPage")
    public AjaxResult listDeptForPage(DeptDto deptDto){
        DataGridView dataGridView = deptService.listDeptForPage(deptDto);
        return AjaxResult.success("查询成功",dataGridView.getData(),dataGridView.getTotal());
    }

    /**
     * 查询所有科室
     * @return
     */
    @GetMapping("selectAllDept")
    public AjaxResult selectAllDept() {
        List<Dept> list = deptService.selectAllDept();
        return AjaxResult.success(list);
    }

    /**
     * 添加科室
     * @param deptDto
     * @return
     */
    @PostMapping("addDept")
    public AjaxResult addDept(@Validated DeptDto deptDto){
        deptDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(deptService.addDept(deptDto));
    }

    /**
     * 修改科室
     * @param deptDto
     * @return
     */
    @PutMapping("updateDept")
    public AjaxResult updateDept(@Validated DeptDto deptDto){
        deptDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(deptService.updateDept(deptDto));
    }

    /**
     * 根据ID批量删除科室
     * @param ids
     * @return
     */
    @DeleteMapping("deleteDeptByIds/{ids}")
    public AjaxResult deleteDeptByIds(@PathVariable Long[] ids){
        return AjaxResult.toAjax(deptService.deleteDeptByIds(ids));
    }
}
